package com.wn.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn.mapper.MoveMapper;
import com.wn.pojo.Move;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MoveService {

    @Autowired
    private MoveMapper moveMapper;

    public Map<String, Object> order(Move move){
        Map<String,Object> map= new HashMap<>();
        move.setStatus("未处理");
        int add = moveMapper.add(move);
        if(add==0){
            map.put("code",1);
            map.put("msg","预约失败");
        }else{
            map.put("code",0);
            map.put("msg","预约成功");
        }
        return map;
    }

    //查询所有（admin）
    public PageInfo getProductByPage(Integer page, Integer limit){
        PageHelper.startPage(page,limit);
        List<Move> list = moveMapper.getProductByPage();
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    //获取总的行数（admin）
    public int getCount() {
        int count = moveMapper.getCount();
        return count;
    }

    //修改
    public Map<String,Object> update(Move move){
        Map<String,Object> map= new HashMap<>();
        int update = moveMapper.update(move);
        if(update==0){
            map.put("code",1);
            map.put("msg","修改失败");
        }else{
            map.put("code",0);
            map.put("msg","修改成功");
        }
        return map;
    }

    public Map<String,Object> xiang(Integer id){
        Map<String,Object> map= new HashMap<>();
        Move move = moveMapper.selectById(id);
        if(StringUtils.isEmpty(move)){
            map.put("code",1);
            map.put("msg","查看失败");
        }else{
            map.put("code",0);
            map.put("data",move);
        }
        return map;
    }
}
